package ten;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class test {
    public static void main(String[] args) {

        String[] str = {"1","2","3"};
        for (String item:str
             ) {
            System.out.println(item);
        }
        ArrayList<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("3");
        for (String destination : list) {
            System.out.println(destination);
        }



        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        System.out.println(c); //[one, two, three, four, five]

        String[] array = c.toArray(new String[5]); // 用toArray()方法将集合c变成数组    // arraylist.toArray(T[] arr) 用法，T为数组类型

        for (int i = 0; i < array.length; i++) {
            System.out.println("遍历数组的每个数"+array[i]);
        }
        // 不带参数的toArray()使用
        Object[] obj = c.toArray();
        for (int i = 0; i < obj.length; i++) {
            System.out.print("遍历数组的每个数"+obj[i]+",");
        }
        System.out.println(Arrays.toString(obj));

    }

}
